package com.agritech.state;

import com.agritech.machine.AgriculturalMachineContext;

/**
 * 故障状态类
 * 状态模式的具体状态实现
 */
public class BrokenState implements MachineState {
    private String failureReason;

    public BrokenState(String reason) {
        this.failureReason = reason;
    }

    @Override
    public void start(AgriculturalMachineContext context) {
        System.out.println("农机 " + context.getMachine().getId() + " 发生故障: " + failureReason + "，无法启动");
    }

    @Override
    public void stop(AgriculturalMachineContext context) {
        System.out.println("农机 " + context.getMachine().getId() + " 发生故障: " + failureReason + "，已经是停止状态");
    }

    @Override
    public void performTask(AgriculturalMachineContext context, String taskDetails) {
        System.out.println("农机 " + context.getMachine().getId() + " 发生故障: " + failureReason + "，无法执行任务");
    }

    @Override
    public void repair(AgriculturalMachineContext context) {
        System.out.println("农机 " + context.getMachine().getId() + " 开始维修故障: " + failureReason);
        context.setState(new MaintenanceState());
    }
    
    @Override
    public String getStateName() {
        return "故障(" + failureReason + ")";
    }

    public String getFailureReason() {
        return failureReason;
    }
}